*REPLICATION FILES
*Article: Reassessing the Impact of Local Control: When Smaller Local Governments Permit More Housing
*Authors: Martin Vinæs Larsen & Laura Kettel
*Software: STATA 18.0
*This file: Uses datasets "balance", "volatility_pt0-2" and "replication_data" to create all Figures and Tables in main manuscript and online appendix (except Figure 1).
*Dependencies: eststo, sdid

*Remember to set directory correctly*


**** 
use "replication_data.dta", clear
set seed 1234
****


*******************
*EMPIRICAL CONTEXT*
*******************

*FIGURE 2 - JURSIZE
eststo fig1: reg avgpop ib(2005).year##c.treat , cl(kom) 
margins,  over(year treat)
marginsplot, noci scheme(plotplain) title("") xlabel(, labsize(medlarge) nogrid) title(" ") legend(ring(0) pos(1) order(2 "Increased Jurisdiction Size" 1 "No increase")) text( 80000 2001.75 "Jurisdiction Size Increases") xline(2006, lpattern(solid) lcolor(black) lwidth(medium)) plot1opts(msym(O) mfcolor(black*0.01) mcolor(black) msize(medlarge)) plot2opts(msym(O) msize(medlarge) mlcolor(black) mfcolor(black*0.5)) ylabel(0(25000)100000, nogrid) xtitle(" ") ytitle("Average Jurisdiction Size")
graph export "fig2.pdf", replace 

*FIGURE B1 - MOBILITY 
eststo figa1: reg totalflyt ib(2006).year##c.treat , cl(kom) 
margins if year >1995,  over(year treat)
marginsplot, scheme(plotplain) title("") xlabel(, labsize(medlarge) nogrid) title(" ", size(large)) ylabel(8(1)16, labsize(medlarge) nogrid) plot1opts(msym(O) mfcolor(black*0.01) mcolor(black) msize(medlarge)) plot2opts(msym(O) msize(medlarge) mlcolor(black) mfcolor(black*0.5))  legend(ring(0) pos(1) order(4 "Increased Jurisdiction Size" 3 "No increase")) ytitle("Moves as percent of total population", size(medlarge)) xline(2006, lpattern(solid) lcolor(black) lwidth(medium)) text( 15 2001.5 "Jurisdiction Size Increases") xtitle(" ") ciopts(recast(rarea) lcolor(%0) fcolor(%20))  level(95) name(a, replace) xlabel(1996(5)2021) 
graph export "b1.pdf", replace 

*FIGURE B2 - YEAR ON YEAR VOLATILITY
preserve
la var treatment "D"
la var year "Period"
recode year (1996/1999=0) (2000/2003=1) (2004/2006=2) (2007=.) (2008/2011=3) (2012/2015=4) (2016/2019=5) (2020/2022=6)
collapse yoy treat post, by(kom year)
su yoy
reg yoy post##i.treat if year!=2007   , cl(kom) 
eststo figa2: reg yoy ib(2).year##c.treat   , cl(kom) 
margins,  over(year treat)
marginsplot, scheme(plotplain) title("") xlabel(, labsize(medlarge) nogrid) title(" ", size(large)) ylabel(0(1)8, labsize(medlarge) nogrid) plot1opts(msym(O) mfcolor(black*0.01) mcolor(black) msize(medlarge)) plot2opts(msym(O) msize(medlarge) mlcolor(black) mfcolor(black*0.5))  legend(ring(0) pos(1) order(4 "Increased Jurisdiction Size" 3 "No increase")) ytitle("Avg. absolute year on year changes in revenue", size(medlarge)) xline(2, lpattern(solid) lcolor(black) lwidth(medium)) text( 2.5 1 "Jurisdiction Size Increases") xtitle(" ") ciopts(recast(rarea) lcolor(%0) fcolor(%20))  level(95) name(a, replace) xlabel(0 "96-99" 1 "00-03" 2 "04-06" 3 "08-11" 4 "12-15" 5 "16-19" 6 "20-22") 
graph export "b2.pdf", replace 

*TABLE G8 - FULL MODEL UNDERLYING FIGURE 2
la var treatment "D"
esttab figa2 using "g8.tex", drop(2.year) replace nostar se b(%9.2f) stats(r2_a N, labels("R2" "N") fmt(%9.2f %9.0f)) nonotes addnotes("\scriptsize Robust standard errors clustered at the municipal level in parentheses.") compress title("Full Models Underlying Figure A2 - Avg. Year on Year Volatility } \centering \scriptsize \label{reg8") nogaps label  nomtitle
restore



*********
*RESULTS*
*********


*FIGURE 3 - MAIN EFFECT
gen dv=log(permit+1)-log(n_baseline)+log(1000) //baseline dependent variable
eststo fig2: reg dv ib(2006).year##c.treat , cl(kom) 
margins if year >1995,  over(year treat)
marginsplot, scheme(plotplain) title("") xlabel(, labsize(medlarge) nogrid) title("Market Rate Housing"  " ", size(large)) ylabel(4.61 "100" 5.3 "200" 6.2 "500" 6.9 "1000" 7.6 "2000", labsize(medlarge) nogrid) plot1opts(msym(O) mfcolor(black*0.01) mcolor(black) msize(medlarge)) plot2opts(msym(O) msize(medlarge) mlcolor(black) mfcolor(black*0.5))  legend(ring(0) pos(1) order(4 "Increased Jurisdiction Size" 3 "No increase")) ytitle("Housing Permitted (SQM per 1,000 residents)", size(medlarge)) xline(2006, lpattern(solid) lcolor(black) lwidth(medium)) text( 7.5 2001 "Jurisdiction Size Increases") xtitle(" ") ciopts(recast(rarea) lcolor(%0) fcolor(%20))  level(95) name(a, replace) xlabel(1996(5)2021) 
tempfile temp
postfile results year b se using `temp', replace
reg dv ib(2006).year##i.treat , cl(kom)
forvalues i=1996/2020 {
post results (`i') (_b[`i'.year#1.treat]) (_se[`i'.year#1.treat])
}
postclose results
preserve
use `temp', clear
gen ul=1.96*se+b
gen ll=-1.96*se+b
gen ul2=1.64*se+b
gen ll2=-1.64*se+b
twoway rspike ul ll year, lwidth(medthick) lcolor(black*0.5)  || scatter b year, scheme(plotplain) title("") xlabel(, labsize(medlarge) nogrid) ylabel(, labsize(medlarge) nogrid) ytitle("DiD Coefficient (log)", size(medlarge)) msym(O) msize(medlarge) mlcolor(black) mfcolor(black*0.1) yline(0, lwidth(medthick) lpattern(dot) lcolor(black)) legend(off) xline(2006, lpattern(solid) lcolor(black) lwidth(medium)) name(b, replace) xtitle(" ") lpattern(solid) xlabel(1996(5)2021) 
graph combine a b, scheme(plotplain) col(1) ysize(9) 
graph export "fig3.pdf", replace 
restore

*TABLE G1 - FULL MODEL UNDERLYING FIGURE 1, 2 and A1 
preserve
la var treatment "D"
la var year "Y"
esttab fig1 fig2 figa1 using "/Users/au595748/Dropbox/apps/Overleaf/loc_cont/results/allreg.tex", replace nostar se b(%9.2f) stats(r2_a N, labels("R2" "N") fmt(%9.2f %9.0f)) mtitle("Jurisdiction Size" "Log(Market Rate Permits)" "Movers/Population") nonotes addnotes(" \scriptsize Robust standard errors clustered at the municipal level in parentheses.") compress title("Regression Underlying Jurisdiction Size, Market Rate Housing and Mobility Figures } \centering \scriptsize \label{reg1") nogaps label wide 
restore

*TABLE 1 - ROBUSTNESS
foreach d in permit completed { 
local `d'a1="Logged per capita (baseline)"
g `d'adv=log(`d'+1)-log(n_baseline)+log(1000) 
local `d'c1="Logged per area"
g `d'cdv=log(`d'+1)-log(area)

local `d'e1="Excluding Island Municipalities"
g `d'edv=log(`d'+1)-log(n_baseline)+log(1000) 
local `d'f1="Excluding Copenhagen"
g `d'fdv=log(`d'+1)-log(n_baseline)+log(1000) 
local `d'g1="Detached Single Family Homes"
g `d'gdv=log(`d'_sfh+1)-log(n_baseline)+log(1000) 
local `d'h1="Attached Single Family Homes"
g `d'hdv=log(`d'_rowhouse+1)-log(n_baseline)+log(1000) 
local `d'i1="Multi-family Housing"
g `d'idv=log(`d'_apartments+1)-log(n_baseline)+log(1000)
tsset kom year 
local `d'j1="2005"
g `d'jdv=log(f.`d'+1)-log(n_baseline)+log(1000) 
local `d'k1="2004"
g `d'kdv=log(f2.`d'+1)-log(n_baseline)+log(1000) 
local `d'l1="All Permits"
g `d'ldv=log(`d'_all+1)+log(1000)-log(n_baseline)
local `d'm1="Public Housing"
g `d'mdv=log(`d'_ph+1)+log(1000)-log(n_baseline)
local `d'n1="Excluding Ineligible Municipalities"
g `d'ndv=log(`d'+1)-log(n_baseline)+log(1000) 
local `d'p1="Logged"
g `d'pdv=log(`d'+1)
local `d'q1="Per capita"
g `d'qdv=(`d'/(n_baseline))
}

foreach x in a c e f g h i j k l m n p q  {
	preserve


if "`x'"=="e" {
	drop if  kom==492|kom==563|kom==741|kom==492
}
if "`x'"=="f" {
		drop  if kom<150
}
if "`x'"=="j" {
		drop  if year==2020
}
if "`x'"=="k" {
		drop  if year==2020|year==2019
}
if "`x'"=="n" {
	drop if  kom==492|kom==563|kom==741|kom==492|kom<150
}
eststo permit`x': reg permit`x'dv c.post##c.treat, cl(kom)
local permit`x'2=(_b[c.post#c.treat]) 
local permit`x'3=(_se[c.post#c.treat])
eststo completed`x': reg completed`x'dv c.post##c.treat, cl(kom)
local completed`x'2=(_b[c.post#c.treat]) 
local completed`x'3=(_se[c.post#c.treat])
local completed`x'4=e(N)
sdid permit`x'dv kom year pt, vce(bootstrap) reps(1000)
local spermit`x'2=e(ATT) 
local spermit`x'3=e(se)
sdid completed`x'dv kom year pt, vce(bootstrap) reps(1000)
local scompleted`x'2=e(ATT) 
local scompleted`x'3=e(se)
local scompleted`x'4=e(N)
restore
drop permit`x'dv
drop completed`x'dv
}

//table
file open anyname using "tab1.txt", write text replace //writing table
file write anyname  _newline  _col(0)  "\begin{table} [htbp] \centering \caption{How Robust is the Effect of Jurisdiction Size on the Supply of Housing?} \label{table:robustest} \small  \begin{tabular}{l*{5}{c}} \hline\hline"
file write anyname  _newline  _col(0)  "&\multicolumn{2}{c}{Permits}&\multicolumn{2}{c}{Completed}&\\ \hline"

file write anyname  _newline  _col(0)  "&DiD&SE&DiD&SE&N\\ \hline"
foreach x in a c p q e f n l g h i m j k  {
             
if "`x'"=="a"{
		file write anyname  _newline  _col(0)  "\textit{Definition of the DV}&&&&&\\"

}

if "`x'"=="e"{
	file write anyname  _newline  _col(0)  "\textit{Sample Restrictions}&&&&&\\"
}	
if "`x'"=="l"{
	file write anyname  _newline  _col(0)  "\textit{Type of Construction}&&&&&\\"
}	

if "`x'"=="j"{
	file write anyname  _newline  _col(0)  "\textit{Baseline Year}&&&&&\\"
}	

	
	
file write anyname _newline _col(5) ("\hspace{3mm}`permit`x'1'")  " &" _tab %9.3f  (`permit`x'2') " &" _tab %9.3f  (`permit`x'3') " &" _tab %9.3f  (`completed`x'2') " &" _tab %9.3f  (`completed`x'3') " &" _tab %9.0f (`completed`x'4')  "\\"
}
file write anyname _newline _col(0) "\hline \hline"
file write anyname _newline _col(0) "\multicolumn{4}{l}{Notes: Standard errors clustered at the municipal level.} \end{tabular}\end{table}"
file close anyname



*TABLE F1 - SYNTHETIC CONTROL
file open anyname using "tabf1.txt", write text replace //writing table
file write anyname  _newline  _col(0)  "\begin{table} [htbp] \centering \caption{Replicating Table 1 with Synthetic DiD} \label{table:synth} \small  \begin{tabular}{l*{5}{c}} \hline\hline"
file write anyname  _newline  _col(0)  "&\multicolumn{2}{c}{Permits}&\multicolumn{2}{c}{Completed}&\\ \hline"
file write anyname  _newline  _col(0)  "&DiD&SE&DiD&SE&N\\ \hline"
foreach x in a c p q e f n l g h i m j k  {
             
if "`x'"=="a"{
		file write anyname  _newline  _col(0)  "\textit{Definition of the DV}&&&&&\\"

}

if "`x'"=="e"{
	file write anyname  _newline  _col(0)  "\textit{Sample Restrictions}&&&&&\\"
}	
if "`x'"=="l"{
	file write anyname  _newline  _col(0)  "\textit{Type of Construction}&&&&&\\"
}	

if "`x'"=="j"{
	file write anyname  _newline  _col(0)  "\textit{Baseline Year}&&&&&\\"
}	

	
	
file write anyname _newline _col(5) ("\hspace{3mm}`permit`x'1'")  " &" _tab %9.3f  (`spermit`x'2') " &" _tab %9.3f  (`spermit`x'3') " &" _tab %9.3f  (`scompleted`x'2') " &" _tab %9.3f  (`scompleted`x'3') " &" _tab %9.0f (`scompleted`x'4')  "\\"
}
file write anyname _newline _col(0) "\hline \hline"
file write anyname _newline _col(0) "\multicolumn{6}{l}{Notes: Bootstrapped standard errors. Estimated using the \texttt{sdid} package.} \end{tabular}\end{table}"
file close anyname



*TABLE G3 AND G4 - FULL MODELS UNDERLYING TABLE 1
preserve
la var treatment "D"
la var post "Post-reform"
esttab permita permitc permitp permitq permite permitf permitn permitl permitg permith permiti permitm permitj permitk  using "tabg3.tex", replace nostar se b(%9.2f) stats(r2_a N, labels("R2" "N") fmt(%9.2f %9.0f))  nogaps nonotes addnotes(" \scriptsize Robust standard errors clustered at the municipal level in parentheses.") compress title("Robustness table - Full Model for Permitted Construction} \centering \scriptsize \label{reg3")  label mtitle("Baseline" "Log per area" "Log" "Per Capita" "No Island" "No CPH" "Excl. Ineligible" "All types" "Detached SFH" "Attached SFH" "Multi" "Public" "B05" "B07") nonumber 

esttab completeda completedc completedp completedq completede completedf completedn completedl completedg completedh completedi completedm completedj completedk using "tabg4.tex", replace nostar se b(%9.2f) stats(r2_a N, labels("R2" "N") fmt(%9.2f %9.0f))  mtitle("Baseline" "Log per area" "Log" "Per Capita" "No Island" "No CPH" "Excl. Ineligible" "All types" "Detached SFH" "Attached SFH" "Multi" "Public" "B05" "B07") nonotes addnotes(" \scriptsize Robust standard errors clustered at the municipal level in parentheses.") compress title("Robustness table - Full Model for Completed Construction} \centering \scriptsize \label{reg4") nogaps label  nonumber 
restore
 
**************************
*ALTERNATIVE EXPLANATIONS*
**************************

*FIGURE 4 - COMPARING RETAIL AND MARKET RATE HOUSING
replace dv=log(permit+1)-log(n_baseline)+log(1000)
eststo a1: reg dv c.post##c.treat , cl(kom) 
margins, over(post treat)
local y0=_b[c.treatment]+_b[_cons]
local y1=_b[c.treatment]+_b[_cons]+_b[c.post]
marginsplot,  ///
  scheme(plotplain) recastci(rcap) ciopts(lwidth(medthick) lcolor(black))  addplot(scatteri `y0' 0  `y1' 1, lwidth(medthick) recast(connect) ylabel(4.61 "100" 5.3 "200" 6.2 "500" 6.9 "1000" 7.6 "2000", labsize(medlarge) nogrid)  xlabel(0 "Pre-reform" 1 "Post-reform", labsize(medlarge) nogrid) below ) title("Market Rate Housing", size(large))  plot2opts(msym(O) msize(large) mlcolor(black) mfcolor(black*0.5)) plot1opts(msym(O) mfcolor(black*0.01) mcolor(black) msize(large)) ytitle("Permits (SQM per 1,000 residents)", size(medlarge))   xtitle(" ") name(a, replace) xoverhangs text(6.5 .5 "counterfactual trend", size(small) color(black*.5)) legend(off)
replace dv=log(permit_retail+1)-log(n_baseline)+log(1000)
eststo b1: reg dv c.post##c.treat , cl(kom) 
margins, over(post treat)
local y0=_b[c.treatment]+_b[_cons]
local y1=_b[c.treatment]+_b[_cons]+_b[c.post]
marginsplot,  ///
  scheme(plotplain) ciopts(lwidth(medthick) lcolor(black)) recastci(rcap) addplot(scatteri `y0' 0  `y1' 1, recast(connect) lwidth(medthick) ylabel(2.3 "10" 3 "20" 3.9 "50" 4.61 "100" 5.3 "200" 6.2 "500", labsize(medlarge) nogrid)  xlabel(0 "Pre-reform" 1 "Post-reform", labsize(medlarge) nogrid) legend(order(4 "Increased Jurisdiction Size" 3 "No increase") ring(0) pos(5)) below) title("Retail and Office Space", size(large))  plot2opts(msym(O) msize(large) mlcolor(black) mfcolor(black*0.5)) plot1opts(msym(O) mfcolor(black*0.01) mcolor(black) msize(large))  xtitle(" ") name(b, replace) legend(order(4 "Increased Jurisdiction Size" 3 "No increase") ring(0) pos(5))ytitle(" ") xoverhangs text(4.35 .5 "counterfactual trend", size(small) color(black*.5) angle(-10))
graph combine a b, scheme(plotplain)
graph export "fig4.pdf", replace 

*TABLE F5 - FULL MODEL UNDERLYING FIGURE 4 
preserve
la var post "Post-reform"
la var treatment "D"
esttab a1 b1 using "tabf5.tex", replace nostar se b(%9.2f) stats(r2_a N, labels("R2" "N") fmt(%9.2f %9.0f))  mtitle("Log(Market Rate Permits)" "Log(Retail and Office Permits)") nonotes addnotes(" \scriptsize  Robust standard errors clustered at the municipal level in parentheses.") compress title("Regressions Underlying Retail and Market Comparison Figure?} \centering \scriptsize \label{reg2") nogaps label 
restore 



*TABLE 2 - MECHANISMS
preserve
rename dosage_vol vol
rename dosage_a ar
rename dosage_p size
bysort kom: egen gnspris=mean(logpris) if year <2006
bysort kom: egen gnspris_all=mean(gnspris)
egen preis=cut(gnspris_all), group(2)
replace preis=preis+1

reg dv c.post##c.ar , cl(kom)  
reg dv c.post##c.size , cl(kom)  
reg dv c.post##c.preis , cl(kom)  

foreach t in vol ar size preis { 
foreach z in permit completed {
replace dv=log(`z'+1)-log(n_baseline)+log(1000) 
reg dv post##treat if `t'!=1 & `t'!=., cl(kom)
local h`t'_`z'=_b[1.post#1.treat]
local h`t'_se_`z'=_se[1.post#1.treat]
reg dv post##treat if `t'!=2 & `t'!=., cl(kom)
local l`t'_`z'= _b[1.post#1.treat]
local l`t'_se_`z'=_se[1.post#1.treat]
if "`t'"!="preis"{
eststo `z'_a_`t':	reg dv c.post##`t', cl(kom)
local `t'_n_`z'=e(N)
test c.post#1.`t'==c.post#2.`t'
}
if "`t'"=="preis"{
eststo `z'_a_`t': reg dv c.post##c.treat##c.`t', cl(kom) coeflegend
local `t'_n_`z'=e(N)
test c.post#c.treatment#c.preis
}
local `t'_p_`z'=r(p)
}
}
local far "Increase in Area"
local fvol "Decrease in Volatility"
local fsize "Increase in Population Size"
local fpreis "Pre-reform Price of Housing"
file open anyname using "tab2.txt", write text replace //writing table
file write anyname  _newline  _col(0)  "\begin{table} [htbp] \centering \caption{Where is the effect of the reform largest?} \label{table:mechtest} \small  \begin{tabular}{l*{6}{c}} \hline\hline"
file write anyname  _newline  _col(0)  "&\multicolumn{2}{c}{Large}&\multicolumn{2}{c}{Small}&&\\ \hline"

file write anyname  _newline  _col(0)  "&DiD&SE&DiD&SE&Test of difference (p)&N\\ \hline"
file write anyname  _newline  _col(0)  "\textbf{Permits}&&&&&&\\"

foreach d in permit completed  {

foreach x in vol size preis ar  {

file write anyname _newline _col(5) ("\hspace{3mm}`f`x''")  " &" _tab %9.3f  (`h`x'_`d'') " &" _tab %9.3f  (`h`x'_se_`d'') " &" _tab %9.3f      (`l`x'_`d'') " &" _tab %9.3f  (`l`x'_se_`d'')  " &" _tab %9.3f (``x'_p_`d'')  " &" _tab %9.0f (``x'_n_`d'')    "\\"
}
if "`d'"=="permit"{
file write anyname  _newline  _col(0)  "\textbf{Completed}&&&&&&\\"
}
}
file write anyname _newline _col(0) "\hline \hline"
file write anyname _newline _col(0) "\multicolumn{4}{l}{Notes: Robust standard errors clustered at the municipal level.} \end{tabular}\end{table}"
file close anyname

*TABLE G6 - FULL MODEL UNDERLYING TABLE 2
la var treatment "D"
la var vol "Increase in Volatility"
la var size "Increase in Population Size"
la var ar "Increase in Area"
la var preis "High Price"
la var post "Post-reform"


esttab permit_a_vol  permit_a_size  permit_a_preis permit_a_ar completed_a_vol completed_a_size completed_a_preis completed_a_ar   using "tabg6.tex", drop(0.*) order(post treatment) replace nostar se b(%9.2f) stats(r2_a N, labels("R2" "N") fmt(%9.2f %9.0f)) nonotes addnotes("\scriptsize Robust standard errors clustered at the municipal level in parentheses.") compress title("Full Models Underlying Table 2} \centering \scriptsize \label{reg5") nogaps label  mtitle("Permit" "Permit" "Permit" "Permit" "Complete" "Complete" "Complete" "Complete") 
restore

*TABLE 3 - CONTROLS
local d="c.net c.logpris c.arb c.logpop " 
local id=0
foreach t in c.net c.logpris c.arb c.logpop  "`d'" { 
local id=1+`id'
foreach z in permit completed {
replace dv=log(`z'+1)-log(n_baseline)+log(1000) 
eststo q`id'_`z'_b: reg dv c.treat##c.post `t', cl(kom)
local h`id'_`z'=_b[c.treatment#c.post]
local h`id'_se_`z'=_se[c.treatment#c.post]
eststo q`id'_`z'_c: reg dv c.treat##(c.post `t'), cl(kom)
local l`id'_`z'= _b[c.treatment#c.post]
local l`id'_se_`z'=_se[c.treatment#c.post]
local n`id'_`z'=e(N)
eststo q`id'_`z'_a: reg dv c.treat##(c.post) if e(sample)==1, cl(kom)
local s_`z'= _b[c.treatment#c.post]
local s_se_`z'=_se[c.treatment#c.post]
local s_n_`z'=e(N)

}
}
local a1 "Seats for Left Parties (net)"
local a2 "Log(Sales Prices)"
local a3 "Jobs in Municipality"
local a4 "Log(Population Size)"
local a5 "All controls"
file open anyname using "tab3.txt", write text replace //writing table
file write anyname  _newline  _col(0)  "\begin{table} [htbp] \centering \caption{Alternative Explanations for the Reform's Effect} \label{table:alt} \small  \begin{tabular}{l*{6}{c}} \hline\hline"
file write anyname  _newline  _col(0)  "&\multicolumn{2}{c}{Additive Control}&\multicolumn{2}{c}{Interaction}&&\\ \hline"

file write anyname  _newline  _col(0)  "&DiD&SE&DiD&SE&N\\ \hline"
file write anyname  _newline  _col(0)  "\textbf{Permits}&&&&&\\"
foreach d in permit completed  {
foreach x in 1 2 3 4 5  {
file write anyname _newline _col(5) ("\hspace{3mm}`a`x''")  " &" _tab %9.3f  (`h`x'_`d'') " &" _tab %9.3f  (`h`x'_se_`d'') " &" _tab %9.3f      (`l`x'_`d'') " &" _tab %9.3f  (`l`x'_se_`d'')    " &" _tab %9.0f (`n`x'_`d'')    "\\"
}
file write anyname _newline _col(5) ("\hspace{3mm}No Controls")  " &" _tab %9.3f  (`s_`d'') " &" _tab %9.3f  (`s_se_`d'') " &" _tab %9.3f    ". & . &" _tab %9.0f (`s_n_`d'')    "\\"
if "`d'"=="permit"{
file write anyname  _newline  _col(0)  "\textbf{Completed}&&&&&\\"
}
}
file write anyname _newline _col(0) "\hline \hline"
file write anyname _newline _col(0) "\multicolumn{4}{l}{Notes: Robust standard errors clustered at the municipal level.} \end{tabular}\end{table}"
file close anyname


*TABLE F7 - FULL MODELS UNDERLYING TABLE 3
preserve
la var post "Post"
la var treatment "D"
la var netleft "Net Left"
la var logpris "Log(Prices)"
la var logpop "Log(Pop)"
la var arb "Jobs"


esttab  q1_permit_b q1_permit_c q2_permit_b q2_permit_c q3_permit_b q3_permit_c q4_permit_b q4_permit_c  q4_permit_a  using "/Users/au595748/Dropbox/apps/Overleaf/loc_cont/results/allreg6.tex", order(post treatment c.treatment#c.post) replace nostar se b(%9.2f) stats(r2_a N, labels("R2" "N") fmt(%9.2f %9.0f)) nonotes addnotes("\scriptsize Robust standard errors clustered at the municipal level in parentheses.") compress title("Full Models Underlying Table 3 (Permits)} \centering \scriptsize \label{reg6") nogaps label  nomtitle

esttab q1_completed_b q1_completed_c q2_completed_b q2_completed_c q3_completed_b q3_completed_c q4_completed_b q4_completed_c  q4_completed_a  using "/Users/au595748/Dropbox/apps/Overleaf/loc_cont/results/allreg7.tex", order(post treatment  c.treatment#c.post) replace nostar se b(%9.2f) stats(r2_a N, labels("R2" "N") fmt(%9.2f %9.0f)) nonotes addnotes("\scriptsize Robust standard errors clustered at the municipal level in parentheses.") compress title("Full Models Underlying Table 3 (Completed)} \centering \scriptsize \label{reg7") nogaps label  nomtitle

************************
*ONLY APPENDIX ANALYSES*
************************

*TABLE A1- BALANCE
use "balance.dta", clear
// Define the treatment variable and the variables to compare
local vars beskgrundlag proptax inctax violent nonw owner shurb old er indb
local treatvar treat
// Initialize a matrix to store the results
matrix results = J(`=wordcount("`vars'")', 6, .)
local rownames ""
// Loop through each variable
local i = 1
foreach var in `vars' {
    summarize dif_`var' if `treatvar' == 0, meanonly
    local control_mean = r(mean)
    summarize dif_`var' if `treatvar' == 1, meanonly
    local treatment_mean = r(mean)
    summarize `var'2006 if `treatvar' == 0, meanonly
    local control_mean1 = r(mean)
    summarize `var'2006 if `treatvar' == 1, meanonly
    local treatment_mean1 = r(mean)
    ttest dif_`var', by(`treatvar') unequal
	local observations = 98
    local diff = r(mu_2) - r(mu_1)
    local pval = r(p)
    matrix results[`i', 2] = `control_mean1'
    matrix results[`i', 1] = `treatment_mean1'
	matrix results[`i', 4] = `control_mean'
    matrix results[`i', 3] = `treatment_mean'
    matrix results[`i', 5] = `diff'
    matrix results[`i', 6] = `pval'
    local rownames "`rownames' dif_`var'"
    local i = `i' + 1
}
matrix rownames results = `rownames'
matrix colnames results = "Control Mean" "Treatment Mean" "Difference" "P-value"
// Export the matrix as a table
esttab matrix(results, fmt(3)) using "/Users/au595748/Dropbox/apps/Overleaf/loc_cont/results/taba1.tex", ///
    title("Comparing Treated and Untreated Municipalities Before the Reform} \centering \scriptsize \label{balancetable") ///
    collabels("Treatment" "Control" " $\Delta$ Treatment"  " $\Delta$ Control" "Dif-in-dif" "p-value"  ) ///
     label nolegend ///
    nonumber replace addnotes(" \scriptsize N=98, p-value from t-test of difference in means assuming heteroscedasticiy. $\Delta$ Signify ten year changes.")



*TABLE B1 - DESCRIPTIVE TABLES
use "/Users/au595748/Dropbox/New Politics of Housing Market/Paper on Jurisdiction Size/data/tabb1.dta", clear
eststo clear
estpost su permit* completed* imstleft imstright pris n_kom treatment area cdosage_vol yoy totalflyt arb
esttab . using"/Users/au595748/Dropbox/apps/Overleaf/loc_cont/results/descriptives.tex", cells("mean(fmt(2) label(Mean)) sd(fmt(2) label(SD)) min(fmt(2) label(Min)) max(fmt(2) label(Max)) count(fmt(0) label(N))")  nonumber replace label title("Descriptive Statistics} \footnotesize \label{table:descriptives") nomtitles stats( )


*FIGURE C1 - VOLATILITY
use "data/volatility_pt0.dta", clear
su difinc, d //leptokurtic and sd calculation
hist difinc, scheme(plotplain) width(2) bfcolor(white) percent xtitle("Year over Year Changes in Tax Revenue (pct.)") name(a, replace)
use "data/volatility_pt1.dta", clear
pwcorr sumdifinc_old logn
scatter sumdifinc_old logn if logn>7, msym(O) mcolor(black%30)   || lfit sumdifinc_old logn if logn>7, scheme(plotplain) lpattern(solid) lwidth(medthick) ytitle("Volatility in the tax base") xtitle("Log(Jurisdiction Size)") lcolor(black) xlabel(, nogrid) ylabel(,nogrid) legend(off) name(b, replace)
use "data/volatility_pt2.dta", clear
scatter sumdifinc_new sumdifinc_old if sumdifinc_old >.025, msym(O) mcolor(black%30)  scheme(plotplain) lpattern(solid) lwidth(medthick) ytitle(Volatility in the tax base (avg. year over year change)) ytitle("Volatility in the tax base if municipalities amalgamated") xtitle("Actual Volatility in the tax base") lcolor(black) xlabel(.025(.025).15, nogrid) ylabel(.025(.025).15, nogrid) legend(off) name(c, replace)
graph combine a b c, scheme(plotplain) row(3) ysize(11) 
graph export "figc1.pdf", replace 



*FIGURE E1 - BOXPLOTS OF PERMITS
gen permit_pc1000=permit/n_kom* 1000
graph hbox permit_pc1000 if treat==1, over(year)  scheme(plotplain) name(a, replace) ytitle(Permits per 1000 citizens) title("Jurisdiction Size Increases") ylabel(0(1000)6000, nogrid) 
graph hbox permit_pc1000 if treat==0, over(year) scheme(plotplain) name(b, replace)  title("No change in Jurisdiction Size") ytitle(Permits per 1000 citizens) ylabel(0(1000)6000, nogrid) 
graph combine a b, scheme(plotplain) row(1) xsize(7)
graph export "/Users/au595748/Dropbox/apps/Overleaf/loc_cont/results/fige1.pdf", replace 




